/***********************************************************************
** Copyright (C) 2011 Anthony Naddeo <anthony.naddeo@gmail.com>
**
** This file is part of LinkedUp
**
** LinkedUp is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** LinkedUp is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this package; If not, see <http://www.gnu.org/licenses/>.
**
***********************************************************************/
import QtQuick 1.1
import com.meego 1.0

/**
  This class creates a list that offers page functionality

  1 2 3 4 5
  ---------
  x ......
  x ......
  x ......

  The pages will be displayed at the top of the list and will
  serve to send requests for different sections of a feed.
  By default, the results requested start at 0 and go in
  intervals of 10. That can be changed with the start and count
  properties.

  */

Item {
	id: root
	anchors.fill: parent
	anchors.topMargin: borderHeight || 0

	property alias content: contentLoader.item


	/**
	  Properties for the page section.
	  This will be a ListView that is displayed as the
	  header of another ListView dedicated to the main
	  content
	  */
	property string pageQuery : "/people-search/people"
	property string start: "0"
	property string count: "10"
	/**
	  The model that defines the total number of results.
	  This is a model by default because I assume the xml
	  file that you got your content from will also report
	  the total number of resutls.
	  */
	property QtObject customPageModel
	property QtObject pageModel: 	XmlListModel{
		query: root.pageQuery
		xml: contentLoader.item.model.xml
		onXmlChanged: reload()
		XmlRole { name: "numResults"; query: "@total/string()"; isKey: true}
	}
	/**
	  This delegate will make up each individual page
	  */
	property Component pageDelegate: Component{
		PageDelegate{
			onChangePage: {
				root.start = start
				root.count = count
			}
		}
	}
	/**
	  This delegate is actually the ListView that will
	  display all of the pages. It is a Component / delegate
	  so that it can be used as the header of the ListView
	  that displays the main content.
	  */
	property Component pageListDelegate: Component{
		ListView{
			id: pages
			clip: true
			spacing: 5
			height: 80
			model: customPageModel || pageModel
			anchors.left: parent.left
			anchors.right: parent.right
			orientation: ListView.Horizontal
			delegate: pageDelegate

		}
	}

	/*------------------------------------------------------------*/

	/**
	  Properties for the main content. This will be a ListView that
	  will use the page components to form a header that supplies
	  page functionality.
	  */

	property Component contentDelegate
	property QtObject contentModel
	property Component contentList: ListView{
		clip: true
		spacing: 10
		header: pageListDelegate
		width: parent.width
		model: contentModel || undefined
		delegate: contentDelegate || undefined
	}



	/*------------------------------------------------------------*/

	/**
	  Display the contentList
	  */


	Loader{
		id: contentLoader
		anchors.fill: parent
		sourceComponent: root.contentList
	}



}
